#!/bin/bash
##############################################################################
# This script is run via /etc/init.d/fppinit at system boot to allow us to
# initialize certain things before the system starts booting.
##############################################################################
# NOTE: The ONLY supported action currently is 'start', so if we're called
#       with anything else, we exit
if [ "x$1" != "xstart" ]
then
	echo "$0 called with unsupported action of '$1'."
	exit 0
fi
#
##############################################################################
# Some internal setup
PATH="/sbin:/bin:/usr/sbin:/usr/bin"

BINDIR=$(cd $(dirname $0) && pwd)

. ${BINDIR}/common
. ${BINDIR}/functions

##############################################################################
echo "    - Checking SSH keys"
SSHKEYS=$(ls -al /etc/ssh/ssh_host*key* 2> /dev/null | wc -l)
if [ ${SSHKEYS} -eq 0 ]
then
	echo "      - Renerating SSH keys"
	ssh-keygen -A
fi
##############################################################################

# Run any user boot-time scripts
runBootHookScripts

# On systems running Stretch, the fpp_init is called prior to network
# so we can use the opportunity to configure the network adapapters
# and DNS and other hardware
.  ${BINDIR}/init_pre_network
